var encodeHTML = function(s) { return s.replace(/\&/g, '&') .replace(/\"/g, '"') .replace(/\'/g, ''') .replace(/\/g, '>'); }; function deferred() { var callbacks = { done: [], fail: [] }; var promise = { done: function(callback) { callbacks.done.push(callback); return promise; }, fail: function(callback) { callbacks.fail.push(callback); return promise; } }; return { resolve: function() { var i = 0, cb; for(;cb = callbacks['done'][i++];) { cb.apply(this, arguments); } }, reject: function() { var i = 0, cb; for(;cb = callbacks['fail'][i++];) { cb.apply(this, arguments); } }, promise: promise }; } ; function asyncRequest(url, params, method) { var defer = deferred(); var xhr = null; var t = (method || 'get').toLowerCase(); xhr = $.ajax({ url: url, type: t, dataType: 'json', data: (t === 'post')? $.extend(params, {ck: get_cookie('ck')}) : params, error: function(e) { defer.reject(e); }, success: function(e) { defer.resolve(e); } }); defer.promise.abort = function() { xhr && xhr.abort(); } return defer.promise; } ; var DOULIST_ADDITEM = '/j/doulist/{doulist_id}/additem'; var DOULIST_REMOVEITEM = '/j/doulist/{doulist_id}/removeitem'; var DOULIST_EDITITEM = '/j/doulist/{doulist_id}/edititem'; var DOULIST_COMMENT = '/j/doulist/{doulist_id}/poke'; var DOULIST_CREATE = '/j/doulist/add'; var DOULIST_LIST = '/j/doulist/cat'; var DOULIST_SEARCH = '/j/doulist/search'; var DOULIST_SEARCH_SELF = '/j/doulist/search_user_doulists'; var DOULIST_GET_ITEM_INFO = '/j/doulist/get_item_info'; var SUBJECT_DOULIST_LIST = '/j/doulist/subject_doulists'; // 片单|书单 ; var validateForm = function(frm, rules) { var bool = true; var inp; for (var n in rules) { if (rules.hasOwnProperty(n)) { inp = frm.find(n); bool = rules[n](inp); if (bool) { validateForm.cleanError(inp); } } } return bool; }; validateForm.displayError = function(inp, error) { if (!inp) { return; } var item = inp.closest('.item'); var errorNode = item.find('.form-field-error'); if (errorNode.length === 0) { errorNode = $('
').prependTo(item); } errorNode.show().html(error); }; validateForm.cleanError = function(inp) { inp.closest('.item').find('.form-field-error').hide(); }; function doulistCustomeEvents(dialog) { var cancelBtn = dialog.node.find('.bn-cancel'); dialog.node.bind('dialog-error', function(e, error) { dialog.setContent( '

' + error + '

\
\ \
\
\ ' ).update(); cancelBtn.click(function() { dialog.close(); }); setTimeout(function() { dialog.close(); }, 3000); }); dialog.node.bind('dialog-success', function(e, doulist) { title = doulist.__title || "添加成功" action = doulist.__action || '已经添加到 ' + doulist.name + ''; dialog.setTitle(title).setContent( '
\ ' + action + '\
\

窗口将在3秒后关闭

\ \
\
\ ' ); cancelBtn = dialog.node.find('.bn-cancel'); cancelBtn.click(function() { dialog.close(); timer && clearTimeout(timer); }); var num = dialog.node.find('.num') , count = num.text() , countdown, timer ;(function() { countdown = countdown || arguments.callee; timer = setTimeout(function() { num.text(--count); count? countdown(): dialog.close(); }, 1000); })(); }); } ; var doulistDialogForm = typeof doulistDialogForm === 'undefined'? {} : doulistDialogForm ;(function() { var initForm = function(dialog) { var frm = dialog.node.find('form'); frm.submit(function(e){ e.preventDefault(); var frmData = { subjectId: frm.find('input[name=subject_id]').val(), subjectKind: frm.find('input[name=subject_kind]').val(), subjectUrl: frm.find('input[name=subject_url]').val(), subjectIsUrlSubject: frm.find('input[name=subject_is_url_subject]').val() == "true", comment: frm.find('textarea[name="comment"]').val(), sync: frm.find('#dlg-opt-share').attr('checked')? '1': '' }; existListHandler(dialog, frm, frmData) .bind('form-submit-error', function(e, error) { dialog.node.trigger('dialog-error', error); }) .bind('form-submit-success', function(e, doulist) { dialog.node.trigger('dialog-success', doulist); }) }); frm.bind('form-submit-fail', function(e, msg){ validateForm.displayError(frm.find('input[name=dl_title]'), msg); }); doulistCustomeEvents(dialog); } function existListHandler(dialog, frm, frmData) { var doulistSelect = frm.find('input[name=dl_id]:checked'); var doulistId = doulistSelect.val(); var doulistName = doulistSelect.next().find('b').text(); var validateRules = { '.dl_exist_select input:checked': function(e) { if (!e.length) { validateForm.displayError($('.dl_exist_select'), '请选择一个豆列'); return false; } return true; } } if(!doulistId && window.hasCancelCollectAction === true){ var obj = { __title: "取消收藏成功", __action: "已经取消了收藏" } setTimeout(function(){ frm.trigger('form-submit-success', obj); }, 500) window.update_collect_state && window.update_collect_state(false); window.hasCancelCollectAction = null; return frm; } if (validateForm(frm, validateRules)) { var data = { /* local-dev // sid: '25839662', // movie // sid: '24879016', // book */ sid: frmData.subjectId, skind: frmData.subjectKind, comment: frmData.comment, sync_to_mb: frmData.sync } if(frmData.subjectIsUrlSubject){ data.surl = frmData.subjectId delete data.sid delete data.skind } asyncRequest( DOULIST_ADDITEM.replace('{doulist_id}', doulistId), data, 'post' ).done(function(res) { if (res.r) { frm.trigger('form-submit-error', res.err); return; } res.sid = frmData.subjectId; res.doulist_id = doulistId; res.name = $.trim(encodeHTML(doulistName)); window.update_collect_state && window.update_collect_state(true); frm.trigger('form-submit-success', res); }); } return frm; } doulistDialogForm.initForm = initForm; })() ; // ref: docs/widgets/doulist_btn.html ;(function($){ var current_doulist_dialog; window.hasCancelCollectAction = null; var params = window.collect_target || {}; if (!params.limit) { params.limit = 10; } params.start = 0; /* local-dev */ // params.tkind = '1001' // params.tid = '33387422' var pureDoulistParams = { tkind: params.tkind, tid: params.tid, start: 0, limit: params.limit }; var searchParams = { start: 0, limit: params.limit } var total; var pureDoulistTotal; var searchDoulistTotal; var status = ''; var pureDoulistStatus = ''; var searchDoulistStatus = ''; var allSubjectDoulsitLoaded = false; var searchKeyword = '' var noMoreSearchResult = false; var inputLock = false; var DOULIST_ITEM_TMPL = '\
\ \ \
'; var loader = '
'; function debounce(func, wait, immediate) { var timeout; return function() { var context = this, args = arguments; var later = function() { timeout = null; if (!immediate) func.apply(context, args); }; var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); }; }; var DOULIST_CATEGORY_TEXT = { 'movie': '片单', 'tv': '片单', 'book': '书单' } function getDigestTypeText(type) { var text = type && DOULIST_CATEGORY_TEXT[type] ? DOULIST_CATEGORY_TEXT[type] : ''; return text; } function isStartsWithPrefixWord(str, type) { var separator = ['|', '丨', '|']; // 三种不同类型的分隔符 return separator.some((sep) => { var reg = new RegExp('^' + getDigestTypeText(type) + "\\" + sep); return reg.test(str); }) }; function DoulistDialog(node, config) { showDoulistDialog(config); node.trigger('dialog:show', current_doulist_dialog); getAllDoulist(config, function() { handleDoulist(config); handleNewDoulist(config); handleDoulistSearch(config); handleCancelCollect(config); handleSelectDoulist(config); }); doulistDialogForm.initForm(current_doulist_dialog); } function showDoulistDialog(config) { if (current_doulist_dialog) { current_doulist_dialog.close(); } config.picture = config.picture || '/pics/sns/doulist_article.png'; /* local-dev */ // config.cate = '1001' var header = config.cate === '1001' ? '

选择书单

\ ' : config.cate === '1002' ? '

选择片单

\ ' : '

选择豆列

\ '; var title = config.cate === '1001' ? '输入新书单名称' : config.cate === '1002' ? '输入新片单名称' : '输入新豆列名称' var dialog = current_doulist_dialog = dui.Dialog({ title: config.cate === '1002' ? '添加到片单' : config.cate === '1001' ? '添加到书单' : '收藏到豆列', width: 640, cls: 'dialog-doulist', content: (config.canview === 'False' ? '
啊,该内容你没有权限查看或已被作者删除。
' : '
\
\
\
\

{{title}}

\
\
\
\
\ \ ×' + header + '
\
\
\ \
\
\ 加载中...\
\
\
\
\
\

推荐语(选填)

\
\ \
\ \ \ \ \ \
\
\
\ 小工具:从浏览器直接把网页内容加入豆列\ \ \
\
\ ').replace(/{{[^{}]+}}/g, function(match) { return (encodeHTML(config[match.replace(/[{}]/g, "")]+"").toString()); }) }, true).open(); dialog.update(); dialog.node.bind('dialog:close', function() { dialog.node.remove(); }); dialog.node.bind('dialog:change', function() { dialog.update(); }); // 重置一下各项参数 params.tkind = config.cate; params.tid = config.id; params.start = 0; pureDoulistParams.tkind = config.cate; pureDoulistParams.tid = config.id; pureDoulistParams.start = 0; searchParams.start = 0; status = ''; pureDoulistStatus = ''; searchDoulistStatus = ''; allSubjectDoulsitLoaded = false; clearSearch(); } // 获取包含书单、片单的全部豆列 function getAllDoulist(config, callback) { if (config.cate === '1001') { getMixedDoulist('book', callback); } else if (config.cate === '1002') { getMixedDoulist('movie', callback); } else { getMixedDoulist('common', callback); } } // 获取已有的片单/书单 function getMixedDoulist(category, callback) { var appendPureDoulists = function() { if (pureDoulistParams.start >= pureDoulistTotal || pureDoulistStatus === 'pending') { return; } pureDoulistStatus = 'pending'; $('.dl_exist_select').append(loader); asyncRequest(DOULIST_LIST, { tkind: pureDoulistParams.tkind, tid: pureDoulistParams.tid, start: pureDoulistParams.start, limit: pureDoulistParams.limit }) .done(function(pureDoulistResp) { var DL_TMPL = DOULIST_ITEM_TMPL; // 直接请求纯豆列,并且是第一次加载的时候 if (pureDoulistParams.start === 0 && category === 'common') { if (pureDoulistResp.total) { var DL_STR = '
'; $(pureDoulistResp.doulist).each(function(i, dl) { DL_STR += DL_TMPL.replace(/{{[^{}]+}}/g, function(match) { var matched = dl[match.replace(/[{}]/g, "")]; return matched && encodeHTML(matched.toString()) || ""; }); }); DL_STR += '
'; $('
', {'class': 'dl-item dl-item-exist'}).insertAfter($('.dl-item')).append(DL_STR); } else { $('
', {'class': 'dl-item dl-item-exist'}).insertAfter($('.dl-item')).append( '
还未创建豆列
' ); } } else { var DL_STR = ''; $(pureDoulistResp.doulist).each(function(i, dl) { DL_STR += DL_TMPL.replace(/{{[^{}]+}}/g, function(match) { var matched = dl[match.replace(/[{}]/g, "")]; return matched && encodeHTML(matched.toString()) || ""; }); }); $('.dl_exist_select').append(DL_STR); } pureDoulistParams.start = pureDoulistParams.start + pureDoulistParams.limit; pureDoulistTotal = pureDoulistResp.total; pureDoulistStatus = 'success'; $('.dl-item-exist .loading').remove(); settleDoulistItemStatus(category) var dialog = current_doulist_dialog; dialog.node.find('form #doulist_item_comment').val(pureDoulistResp.comment); if (pureDoulistParams.start >= pureDoulistTotal) { $('.dl_exist_select').append('
没有更多了
'); } if (category === 'common') { callback && callback() } }).fail(function() { $('.dl-loading').text('+_+ 加载失败,请刷新重试'); pureDoulistStatus = 'error'; $('.dl-item-exist .loading').remove(); }) } if (allSubjectDoulsitLoaded || category === 'common') { appendPureDoulists(); return; } if (params.start >= total || status === 'pending') { return; } status = 'pending'; $('.dl_exist_select').append(loader); asyncRequest(SUBJECT_DOULIST_LIST, { start: params.start + getJustCreatedNewListsCount(), limit: params.limit, tkind: params.tkind, tid: params.tid }).done(function(resp) { var DL_TMPL = DOULIST_ITEM_TMPL; // 第一次加载的时候 if (params.start === 0) { if (resp.total) { var DL_STR = '
'; $(resp.doulist).each(function(i, dl) { DL_STR += DL_TMPL.replace(/{{[^{}]+}}/g, function(match) { var matched = dl[match.replace(/[{}]/g, "")]; return matched && encodeHTML(matched.toString()) || ""; }); }); DL_STR += '
'; $('
', {'class': 'dl-item dl-item-exist'}).insertAfter($('.dl-item')).append(DL_STR); } else { var typeStr = category === 'book' ? '书单' : category === 'movie' ? '片单' : ''; $('
', {'class': 'dl-item dl-item-exist'}).insertAfter($('.dl-item')).append( '
还未创建' + typeStr + '
' ); } } else { var DL_STR = ''; $(resp.doulist).each(function(i, dl) { DL_STR += DL_TMPL.replace(/{{[^{}]+}}/g, function(match) { var matched = dl[match.replace(/[{}]/g, "")]; return matched && encodeHTML(matched.toString()) || ""; }); }); $('.dl_exist_select').append(DL_STR); } $('.dl_new_title').hide(); params.start = params.start + params.limit; total = resp.total; status = 'success'; $('.dl-item-exist .loading').remove(); settleDoulistItemStatus(category) var dialog = current_doulist_dialog; dialog.node.find('form #doulist_item_comment').val(resp.comment); callback && callback() // 拿到全部的片单/书单后,再去获取纯豆列 if (params.start >= total) { allSubjectDoulsitLoaded = true; if (pureDoulistParams.start === 0) { $('.dl_exist_select').append('
收藏到豆列
') } appendPureDoulists() } }).fail(function() { $('.dl-loading').text('+_+ 加载失败,请刷新重试'); status = 'error'; $('.dl-item-exist .loading').remove(); }); } // 针对列表里单个豆列做修改 function settleDoulistItemStatus(targetCategory, isSearch) { var dialog = current_doulist_dialog; var $items = isSearch ? dialog.node.find('.search-result-list .dl-item-wrap') : dialog.node.find('.dl_exist_select .dl-item-wrap'); $items.each(function(e, doulist) { var $d = $(doulist); var doulist_category = $d.attr('data-category'); var doulist_type = $d.attr('data-doulist-type'); var is_syncing_from_note = $d.attr('data-is-syncing-from-note'); var sync_note_id = $d.attr('data-sync-note-id'); var is_collected = $d.find('.cancel-collect-btn').attr('data-is-collected'); // 如果已经收藏过了,不能再选择 // if (is_collected) { // $d.find('input').attr('disabled', true) // } // 不能直接添加到条目豆列 if (is_syncing_from_note) { $d.find('input').attr('disabled', true); } if (is_syncing_from_note && sync_note_id && targetCategory === doulist_category) { var act = is_collected ? '去移除' : '去添加'; $d.find('span').html('' + act + '>'); } }) } // 获取通过弹窗新建的列表数量,用来在滚动加载时重新计算 start 值 function getJustCreatedNewListsCount() { var dialog = current_doulist_dialog; var dl_exist = $('.dl_exist_select'); var count = 0; dl_exist.find('.dl-item-wrap').each(function(i, item) { if ($(item).hasClass('just-created')) { count++ } }) return count } function handleCancelCollect(config){ var $cancelBtn = $('.cancel-collect-btn'); $cancelBtn.click(function(e){ e.stopPropagation(); e.preventDefault(); if (!confirm("确定要移除吗?")) return; var did = $(this).attr('data-id'); var url = DOULIST_REMOVEITEM.replace('{doulist_id}', did); var param = window.collect_target || {}; var $btn = $(this); param.ck = get_cookie('ck'); param.tkind = config.cate; param.tid = config.id; asyncRequest(url, param, "post").done(function(res){ if (res.r === 0) { $btn.attr('data-is-collected', 'false'); $btn.closest('label').find('span').html(''); var $root = $btn.closest('label').parent(); $root.find('input[type="radio"]').get(0).checked = false; $root.find('input[type="radio"]').attr('disabled', false); $root.removeClass('checked_dl'); window.hasCancelCollectAction = true; } else { alert("取消收藏时遇到了错误: " + res.err); } }) }); } function handleDoulist(config) { var dialog = current_doulist_dialog; var dl_new = $('#dl_new'); var dl_new_title = $('.dl_new_title'); var dl_title = $('#dl_title'); var dl_exist = $('.dl-item-exist'); var dl_id = $('#dl_id'); dl_new.click(function() { var form_error = $('.form-field-error'); if (dl_new_title.is(':hidden')) { form_error.show() && dl_new.val('取消创建'); dl_new_title.slideDown(function() { dl_exist.addClass('fold'); dl_title.focus(); }); } else { var typeStr = config.cate === '1001' ? '书单' : config.cate === '1002' ? '片单' : '豆列'; form_error.hide() && dl_new_title.hide() && dl_new.val('创建' + typeStr) && dl_exist.removeClass('fold'); } }); // 滚动加载 // stop page scrolling dl_exist.bind('scroll', debounce(function(e) { var scrollTop = $(this).scrollTop(); var scrollHeight = $(this).height(); var windowHeight = $(".dl_exist_select:visible").height(); if (scrollTop + scrollHeight + 30 >= windowHeight) { e.preventDefault(); if (dl_exist.find('.search-result-list').size() > 0 && searchDoulistStatus !== '') { searchDoulist(config, true) } else { getAllDoulist(config) } } }, 300)); } function handleSelectDoulist(config) { var dialog = current_doulist_dialog; dialog.node.delegate(':radio', 'change', function() { var $t = $(this); // 排除「新建豆列、片单、书单」表单里的「所有人可见」「仅自己可见」 if ($t.parents('.dl_create_option').size() > 0) { return; } var did = $t.val(); var url = DOULIST_COMMENT.replace('{doulist_id}', did); // 日记同步的豆列不可选 if ($t.parent().attr('data-is-syncing-from-note')) { return; } asyncRequest( url, { /* local-dev */ // sid: '25839662', // movie // sid: '33387422', // book sid: config.id, skind: config.cate } ).done(function(e){ dialog.node.find('form #doulist_item_comment').val(e.comment); }).fail(function(){ // ignore }); }); } function handleNewDoulist(config) { var dialog = current_doulist_dialog; var dl_new_title = $('.dl_new_title'); var dl_title = $('#dl_title'); var dl_new_submit = $('.dl_new_submit'); dl_title.bind('keyup change', function() { if ($.trim(dl_title.val()).length) { dl_new_submit.removeAttr('disabled'); } else { dl_new_submit.attr('disabled', true); } }); dl_title.bind('keydown', function(e) { if (e.keyCode === 13) { newListHandler(dialog, dl_new_title, config); return false; } }); dl_new_submit.click(function() { newListHandler(dialog, dl_new_title, config); }); } function renderSearched(res, category) { var DL_TMPL = DOULIST_ITEM_TMPL; DL_TMPL = DL_TMPL.replace(/value="{{id}}" id="{{id}}"/g, 'value="{{id}}" id="search-{{id}}"').replace(/for="{{id}}"/g, 'for="search-{{id}}"'); var RESULT = ''; $(res.doulists).each(function(i, dl) { RESULT += DL_TMPL.replace(/{{[^{}]+}}/g, function(match) { var matched = dl[match.replace(/[{}]/g, "")]; return matched && encodeHTML(matched.toString()) || ""; }); }); $('.dl-item-exist .search-result-list').append(RESULT); settleDoulistItemStatus(category, true) } function handleDoulistSearch(config) { var dl_search = $('.dl_search'); var dl_exist = $('.dl-item-exist'); var dl_new_title = $('.dl_new_title'); var dl_new = $('#dl_new'); var clear_search_btn = $('.clear_search'); clear_search_btn.click(function() { dl_search.val('').change(); clearSearch() }); dl_search.focus(function() { $(this).addClass('expand'); if (!dl_new_title.is(':hidden')) { var form_error = $('.form-field-error'); var typeStr = config.cate === '1001' ? '书单' : config.cate === '1002' ? '片单' : '豆列'; form_error.hide() && dl_new_title.hide() && dl_new.val('创建' + typeStr) && dl_exist.removeClass('fold'); } }); dl_search.bind({ 'compositionstart': function () { inputLock = true; }, 'compositionend': function () { inputLock = false; }, 'input': function () { setTimeout(() => { if (inputLock) return; var currenKeyword = $.trim(dl_search.val()); if (currenKeyword.length && searchKeyword !== currenKeyword) { noMoreSearchResult = false; searchDoulist(config); } else if (currenKeyword.length === 0) { clearSearch(); } }, 100); } }) } function clearSearch() { var dl_search = $('.dl_search'); var dl_exist = $('.dl-item-exist'); var clear_search_btn = $('.clear_search'); $('.no-match-warning').hide(); dl_exist.find('.dl_exist_select').show(); dl_exist.find('.search-result-list').remove(); searchParams.start = 0; searchDoulistTotal = null; searchDoulistStatus = ''; // dl_exist.children().show(); clear_search_btn.hide(); dl_search.val(''); searchKeyword = ''; currenKeyword = ''; noMoreSearchResult = false; } function show_no_match() { var dl_exist = $('.dl-item-exist'); $('.no-match-warning').length ? $('.no-match-warning').show() : dl_exist.before('

没有找到匹配结果,可以换个关键词试试

'); } function searchDoulist(config, isScrollAppend) { var promise = null; var dl_search = $('.dl_search'); var dl_exist = $('.dl-item-exist'); var dl_new_title = $('.dl_new_title'); var dl_new = $('#dl_new'); var clear_search_btn = $('.clear_search'); var currenKeyword = $.trim(dl_search.val()); if (promise) { promise.abort(); } if (searchDoulistStatus === 'pending' || noMoreSearchResult) { return } $('.no-match-warning').hide(); if (!isScrollAppend) { dl_exist.find('.search-result-list').remove(); } clear_search_btn.hide(); dl_search.addClass('loading'); searchKeyword = currenKeyword; searchDoulistStatus = 'pending'; const category = config.cate === '1001' ? 'book' : config.cate === '1002' ? 'movie' : ''; promise = asyncRequest( DOULIST_SEARCH_SELF, { 'limit': 5, 'start': isScrollAppend ? searchParams.start : 0, 'q': currenKeyword, 'category': category } ); promise.done(function(res) { dl_search.removeClass('loading'); clear_search_btn.show(); searchDoulistStatus = 'success'; if (isScrollAppend) { searchParams.start = searchParams.start + searchParams.limit } if (res && res.doulists && res.doulists.length > 0) { if ($('.dl-item-exist .search-result-list').size() === 0) { $('.dl-item-exist .dl_exist_select').hide().after('
') } renderSearched(res, category) } else { noMoreSearchResult = true; if (searchParams.start === 0) { dl_exist.find('.dl_exist_select').hide(); dl_exist.find('.search-result-list').remove(); show_no_match(); } else { dl_exist.find('.search-result-list').append('
没有更多了
'); } } }).fail(function() { noMoreSearchResult = true; dl_exist.find('.dl_exist_select').hide(); dl_exist.find('.search-result-list').remove(); show_no_match(); dl_search.removeClass('loading'); clear_search_btn.show(); searchDoulistStatus = 'error'; }); } // 表单验证(创建豆列/片单/书单时) function newListHandler(dialog, wrap, config) { var DL_TMPL = '
'; var dl_title = $('#dl_title'); var dl_new = $('#dl_new'); var dl_exist = $('.dl_exist_select'); var validateRules = { '#dl_title': function(e) { if (e.val() === '') { var typeStr = config.cate === '1001' ? '书单' : config.cate === '1002' ? '片单' : '豆列'; validateForm.displayError(e, '请给你的' + typeStr + '起一个名称'); return false; } return true; } } if (validateForm(wrap, validateRules)) { var dl_new_submit = $('.dl_new_submit'); dl_new_submit.attr('disabled', true); var title = $.trim($('#dl_title').val()); var digestType = config.cate === '1001' ? 'book' : config.cate === '1002' ? 'movie' : ''; var prefixWord = getDigestTypeText(digestType) + '|'; // 如果是书单、片单,标题自动加上前缀 if (digestType && !isStartsWithPrefixWord(title, digestType)) { title = prefixWord + title } var params = { title: title, is_private: $('input[name="is_private"]:checked').val(), } if (config.cate === '1001' || config.cate === '1002') { params.category = config.cate === '1001' ? 'book' : 'movie'; } asyncRequest(DOULIST_CREATE, params, 'post') .done(function(res) { if (res.r) { alert(res.err); return; } res.doulist_id = res.id; var DL_STR = DL_TMPL.replace(/{{[^{}]+}}/g, function(match) { var matched = res[match.replace(/[{}]/g, "")]; return matched && encodeHTML(matched.toString()) || ""; }); var new_dl = $(DL_STR); new_dl.prependTo(dl_exist); dl_exist.find('.empty-list').remove(); dl_exist.animate({'scrollTop': 0}, 100); dl_new.click(); dl_title.val('').change(); }) .fail(function() { alert('网络问题,请稍后重试'); dl_new_submit.removeAttr('disabled'); }); } else { dialog.update(); } return wrap; } $.fn.doulistDialog = function(options) { /* local-dev */ // options.cate = "1001" // options.catename = "图书" // options.id = "33387422" return new DoulistDialog($(this), options); }; })(jQuery);